package config

import (
	"fmt"

	"github.com/gin-gonic/gin"
	"github.com/go-ini/ini"
)

var (
	AppMode string
	Port    string
	Address string

	UploadDir string
	ChunkDir  string
	ImagesDir string
	VideosDir string
	LogDir    string
	DataDir   string
)

func init() {
	file, err := ini.Load("config.ini")
	if err != nil {
		panic(fmt.Sprintf("config.ini load failed, err: %s", err))
	}
	loadServer(file)
	loadPath(file)
}

func loadServer(file *ini.File) {
	AppMode = file.Section("service").Key("AppMode").String()
	Port = file.Section("service").Key("Port").String()
	Address = file.Section("service").Key("Address").String()
}

func loadPath(file *ini.File) {
	UploadDir = file.Section("path").Key("UploadDir").String()
	ChunkDir = file.Section("path").Key("ChunkDir").String()
	ImagesDir = file.Section("path").Key("ImagesDir").String()
	VideosDir = file.Section("path").Key("VideosDir").String()
	LogDir = file.Section("path").Key("LogDir").String()
	DataDir = file.Section("path").Key("DataDir").String()
	if gin.Mode() == gin.ReleaseMode {
		UploadDir = DataDir + UploadDir
		ChunkDir = DataDir + ChunkDir
		ImagesDir = DataDir + ImagesDir
		VideosDir = DataDir + VideosDir
		LogDir = DataDir + LogDir
	}
}
